package cn.yuanqiao.common.utils;

import java.util.ArrayList;
import java.util.List;

public class ListUtils {
    public static List<List<Long>> subList(List<Long> target, int size) {
        List<List<Long>> listArr = new ArrayList<List<Long>>();
        //获取被拆分的数组个数
        int arrSize = target.size()%size==0?target.size()/size:target.size()/size+1;
        for(int i=0;i<arrSize;i++) {
            List<Long> sub = new ArrayList<Long>();
            //把指定索引数据放入到list中
            for(int j=i*size;j<=size*(i+1)-1;j++) {
                if(j<=target.size()-1) {
                    sub.add(target.get(j));
                }
            }
            listArr.add(sub);
        }
        return listArr;
    }

    public static <T> List<List<T>> splitListIndependent(List<T> list, int size) {
        List<List<T>> lists = new ArrayList<>();
        for (int i = 0; i < list.size(); i += size) {
            int end = Math.min(i + size, list.size());
            lists.add(new ArrayList<>(list.subList(i, end)));
        }
        return lists;
    }



}
